<?php
namespace Operations\Controller;
use Common\Controller\AdminbaseController;


class GroupsController extends AdminbaseController {
	protected $groups_model,$device_model,$region_model,$groupsdevice_model,$devicetemp_model;

	function _initialize() {
		parent::_initialize();
		$this->store_model = D("Store");
		$this->device_model = D("Device");
		$this->groups_model = D("Groups");
		$this->region_model = D("Region");
		$this->groupsdevice_model = D("GroupsDevice");
		$this->devicetemp_model = D("DeviceTemp");

	}

    private function devicestatus() {
		$devicestatus =
		array(
			array(
		        'ZX' => array('id' => 'ZX','name' => '二代保温箱'),
		        'MX' => array('id' => 'MX','name' => '三代保温箱'),
		        'FX' => array('id' => 'FX','name' => '四代保温箱'),
		        'AD' => array('id' => 'AD','name' => '广告机'),
		        'TA' => array('id' => 'TA','name' => '游戏桌'),
		        'OS' => array('id' => 'OS','name' => '外置摇一摇'),
		        'CS' => array('id' => 'CS','name' => '影院摇一摇'),
		        'CM' => array('id' => 'CM','name' => '自动咖啡机'),
		        'GK' => array('id' => 'GK','name' => '工卡'),
		        'QT' => array('id' => 'QT','name' => '其他设备')
	        ),
	        array(
	            '1'=>array('id' => '1', 'name'=>'停用'),
	            '2'=>array('id' => '2', 'name'=>'激活'),
	            '3'=>array('id' => '3', 'name'=>'损坏'),
	            '4'=>array('id' => '4', 'name'=>'发货'),
	            '5'=>array('id' => '5', 'name'=>'入库'),
	            '6'=>array('id' => '6', 'name'=>'出场'),
	        ),
	        array(
	            '0'=>array('id' => '0', 'name'=>'请选择'),
	            '1'=>array('id' => '1', 'name'=>'条形码'),
	            '2'=>array('id' => '2', 'name'=>'设备ID'),
	            '3'=>array('id' => '3', 'name'=>'设备UUID'),
	            '4'=>array('id' => '4', 'name'=>'major值'),
	            '5'=>array('id' => '5', 'name'=>'minor值'),
	        ),
	        array(
	            array('id' => '1', 'name'=>'指定设备'),
	            array('id' => '2', 'name'=>'选定坐标'),
	            array('id' => '3', 'name'=>'选定城市'),
	            array('id' => '4', 'name'=>'批量导入'),
	        ),
	        array(
				'100'=>array('id'=>'100','name'=>'电影院'),
				'105'=>array('id'=>'105','name'=>'私人影吧'),
				'110'=>array('id'=>'110','name'=>'奶茶/水吧'),
				'120'=>array('id'=>'120','name'=>'商超'),
				'125'=>array('id'=>'125','name'=>'KTV'),
				'130'=>array('id'=>'130','name'=>'便利店'),
				'135'=>array('id'=>'135','name'=>'烘培蛋糕店'),
				'140'=>array('id'=>'140','name'=>'西餐厅/中餐厅'),
				'150'=>array('id'=>'150','name'=>'咖啡/甜品店'),
				'160'=>array('id'=>'160','name'=>'酒吧/夜店'),
				'170'=>array('id'=>'170','name'=>'小吃店/零食店'),
				'180'=>array('id'=>'180','name'=>'网咖/网吧'),
				'190'=>array('id'=>'190','name'=>'主题公园/景区'),
				'200'=>array('id'=>'200','name'=>'副食品店'),
				'500'=>array('id'=>'500','name'=>'其他'),
			)
		);
		return $devicestatus;
    }

	public function getArr( $file ){
        if(!file_exists( $file )){
            return false;//判断文件是否存在
        }
        $arr = file($file);
        $res = array();
        foreach($arr as $value){
            $value = trim( $value );
            if( empty($value)){
                continue;//去除空行
            }
			$value=explode(",", str_replace(array("\r\n", "\r", "\n","\"","\'","，","。"), "", $value));
			$res[] = $value;//确定第二维度
		}
        return $res;
    }
	function expChangeCode($data){
		$encode = mb_detect_encoding($data, array("ASCII",'UTF-8','GB2312',"GBK",'BIG5'));
		if($encode=="UTF-8"){
		        return $data;
		}else{
				$data = eval('return '.iconv('gbk','utf-8',var_export($data,true)).';');
		        return $data;
		}
    }
	function index(){
		$this->_lists();
		$this->display();
	}

	function _lists(){
		if(!get_current_adminug_id() && get_current_adminrole_id() > 9){
            $search[] = array('id'=>0);
            $_GET['id'] = 0;
		}elseif(get_current_adminug_id() && get_current_adminrole_id() > 9){
            $search[] = array('ugid'=>get_current_adminug_id());
            $_GET['ugid'] = get_current_adminug_id();
		}
		if(I('param.')){
            if(I('param.area_type')){
                    $search[] = array('area_type'=>I('param.area_type'));
                    $_GET['area_type'] = I('param.area_type');
            }
            if(I('param.start_time')){
                    $search[] = array('date(created)'=>array('egt',I('param.start_time')));
                    $_GET['start_time'] = I('param.start_time');
            }
            if(I('param.end_time')){
                    $search[] = array('date(created)'=>array('elt',I('param.end_time')));
                    $_GET['end_time'] = I('param.end_time');
            }
            if(I('param.keyword')){
                    $search[] = array('area_name'=>array("like","%".I('param.keyword')."%"));
                    $_GET['keyword'] = I('param.keyword');
            }
		}
		$count = $this->groups_model->where($search)->count();
		$page = $this->page($count, 50);
		$areas = $this->groups_model->where($search)->order("id DESC")->select();
		if($areas){
			foreach($areas as$auser){
				$uid[] =$auser['userid'];
			}
			$users=M("users")->field("id,user_login")->where(array('id'=>array('in',$uid)))->select();
		}
		$this->assign("users", $users);
		$bstatus = $this->devicestatus();
		$this->assign("bstatus", $bstatus[3]);
		$this->assign("areas", $areas);
		$this->assign("page", $page->show('Admin'));
		$this->assign("count", $count);
	}

	function add(){
		$this->display();
	}

	function add_device(){
		if(!I('param.aid')){
			$_GET['area_name']=I('param.area_name');
			$_GET['area_description']=I('param.area_description');
			$_GET['locking']=I('param.locking');
		}else{
			$_GET['aid']=I('param.aid');
			$nowareaidevice = $this->groupsdevice_model->where(array("aid"=>I('param.aid')))->select();
			foreach($nowareaidevice as$k=>$areadevice){
				$now[$k] = $areadevice['bid'];
			}
		}
			$_GET['area_type']=I('param.area_type');
		if(I('get.source')){
			$_GET['source']=I('get.source');
			$source =I('get.source');
		}
		if(I('param.source')){
			$_GET['source']=I('param.source');
			$source =I('param.source');
		}
		$this->assign("source", $source);
		if(I('param.area_type')==1){
			if(I('param.')){
				$keyword =I('param.keyword');
				if(I('param.search') ==1){$search[] = array('barcode'=>array('like',"%$keyword%"));}
				if(I('param.search') ==2){$search[] = array('devid'=>array('like',"%$keyword%"));}
				if(I('param.search') ==3){$search[] = array('uuid'=>array('like',"%$keyword%"));}
				if(I('param.search') ==4){$search[] = array('major'=>array('like',"%$keyword%"));}
				if(I('param.search') ==5){$search[] = array('minor'=>array('like',"%$keyword%"));}
	            if(I('param.dtype')){
	            	$dtype =I('param.dtype');
	                $search[] = array('dtype'=>$dtype);
	            }
				if($now){
					$search[] = array('id'=>array('NOT IN',$now),'status'=>2);
				}else{
					$search[] = array('status'=>2);
				}
	            $_GET['dtype'] = I('param.dtype');
	            $_GET['status'] = I('param.status');
				$_GET['search']=I('param.search');
				$_GET['keyword']=I('param.keyword');
			}else{
				if($now){
					$search[] = array('id'=>array('NOT IN',$now),'status'=>2);
				}else{
					$search[] = array('status'=>2);
				}
			}
			$count=$this->device_model->where($search)->count();
			$page = $this->page($count,50);
			$devices=$this->device_model->where($search)
					->limit($page->firstRow . ',' . $page->listRows)
					->order("id DESC")
					->select();
			if($devices){
				foreach($devices as $device){
					$store_id[] = $device['store_id'];
				}
				$stores=$this->store_model->where(array('osid'=>array('in',$store_id)))->select();
				$this->assign("stores", $stores);
			}
			$bstatus = $this->devicestatus();
			$this->assign("search", $bstatus[2]);
			$this->assign("bstatus", $bstatus[1]);
			$this->assign("stype", $bstatus[4]);
			$this->assign("dtype", $bstatus[0]);
	    	$this->assign('page', $page->show('Admin'));
			$this->assign("devices", $devices);
			$this->assign("count", $count);
		}
		if(I('param.area_type')==2){

		}
		if(I('param.area_type')==3){
			if(I('param.province')){
				$province = I('param.province');
				$_GET['province']=I('param.province');
			}if(I('param.city')){
				$city = I('param.city');
				$_GET['city']=I('param.city');
			}if(I('param.county')){
				$county = I('param.county');
				$_GET['county']=I('param.county');
			}if(I('param.province') == 0){
				$city = $_POST['city'] = $_GET['city'] = 0;
			}
			$provinceid = $this->region_model->where(array('parent_id'=>100000))->select();
			$this->assign("province", $provinceid);
			$cityid = $this->region_model->where(array('parent_id'=>$province))->select();
			$this->assign("city", $cityid);
			$countyid = $this->region_model->where(array('parent_id'=>$city))->select();
			$this->assign("county", $countyid);
		}
		if(I('param.area_type')==4){

		}
		$this->display();
	}
	function add_post(){
		if(IS_POST){
			if(!get_current_adminug_id() && get_current_adminrole_id() > 9){
				$this->error("您不属于任何组，请先创建组");
			}
			if($this->groups_model->where(array('area_name'=>I("post.area_name")))->find()){
				$this->error("此区域名称已存在。");
			}
				$area['area_name']=I('param.area_name');
				$area['area_type']=I('param.area_type');
				if(I('param.area_type') == 1){
					$bid = I('param.bid');
					$area['area_quantity']=count($bid);
					$bstatus = $this->devicestatus();
					$value_a = I('param.dtype').'~'.$bstatus[2][I('param.search')]['name'].':'.I('param.keyword');
					$value_b=date("Y-m-d H:i:s");
					$value_c=get_client_ip(0,true);
					$value_d=get_current_admin_id();
				}
				if(I('param.area_type') == 2){
					$value_a = I('param.lt_through').','.I('param.lt_latitude');
					$value_b = I('param.rt_through').','.I('param.rt_latitude');
					$value_c = I('param.rb_through').','.I('param.rb_latitude');
					$value_d = I('param.lb_through').','.I('param.lb_latitude');
					$bid[0]=1;
					$area['area_quantity']=1;
				}
				if(I('param.area_type') == 3){
					if(I('param.province')){
						$provinceid = $this->region_model->where(array('code'=>I('param.province')))->find();
						$where= array('province_id'=>$provinceid['code']);
						if(I('param.city')){
							$cityid = $this->region_model->where(array('code'=>I('param.city')))->find();
							$where= array('province_id'=>$provinceid['code'],'city_id'=>$cityid['code']);
							if(I('param.county')){
								$countyid = $this->region_model->where(array('code'=>I('param.county')))->find();
								$where= array('province_id'=>$provinceid['code'],'city_id'=>$cityid['code'],'district_id'=>$countyid['code']);
							}
						}
						$bid[0]=1;
					}else{
						$this->error("请先选择省份");
					}
					$value_a = $provinceid['code'];
					$value_b = $cityid['code'];
					$value_c = $countyid['code'];
					$value_d = $provinceid['name'].','.$cityid['name'].','.$countyid['name'];
					$area['area_quantity']=1;
				}
				if(I('param.area_type') == 4){
					$this->devicetemp_model->where(array('barcode is not NULL'))->delete();
					setlocale(LC_ALL, 'en_US.UTF-8');
					if($_FILES["inputcsv"]["name"]){
						$path1 = $_FILES["inputcsv"]["name"];
						$path2 =time().substr($path1,strpos($path1,'.'));
					if(substr($path1,strpos($path1,'.'))!='.csv'){
					   	$this -> error('文件格式不正确');
						}
					}
					if($_FILES["inputcsv"]["size"]>256000){
						$this -> error('文件大小不得超过256KB');
					}
					move_uploaded_file($_FILES["inputcsv"]["tmp_name"],RUNTIME_PATH.$path2);
					$file = RUNTIME_PATH.$path2;
					$arr = $this->getArr($file);
					$carr =count($arr);
					if($carr >=2000){
					   	$this -> error('文件内容过多，请拆分文件导入');
					}
					$ca = count($arr[0]);
					for($i=1;$i<$carr;$i++){
						$str=$device=null;
						for($j=0;$j<$ca;$j++){
							$str[] = $this->expChangeCode($arr[$i][$j]);
						}
						$device['barcode'] = $str[0];
						$device['devid'] = $str[1];
						$this->devicetemp_model->add($device);
					}

						$deviceids = $this->device_model
						->field('d.id')
						->table('yy_device AS d,yy_device_temp AS dt')
						->where("(d.barcode= dt.barcode or d.devid= dt.devid) and d.status=2")
						->select();
					foreach($deviceids as$deviceid){
						$bid[]=$deviceid['id'];
					}
					$area['area_quantity']=count($bid);
					$value_a='导入数据';
					$value_b=date("Y-m-d H:i:s");
					$value_c=get_client_ip(0,true);
					$value_d=get_current_admin_id();
				}
				$area['area_description']=I('param.area_description');
				$area['area_locking']=I('param.area_locking');
				$area['status']=0;
				$area['created']=date("Y-m-d H:i:s");
				$area['created_by']=get_current_admin_id();
				$area['userid']=get_current_admin_id();
				$area['ugid'] = get_current_adminug_id();

				if(I('param.area_locking')){
					$this->groupsdevice_model->where(array('bid'=>array('in',$bid)))->delete();
					$this->device_model->where(array('id'=>array('in',$bid)))->save(array('locking'=>'1'));
				}
				$areaid = $this->groups_model->add($area);
				if($bid){
					foreach($bid as$k=>$id){
						$abid[$k]['aid'] = $areaid;
						$abid[$k]['bid'] = $id;
						$abid[$k]['value_a'] =$value_a;
						$abid[$k]['value_b'] =$value_b;
						$abid[$k]['value_c'] =$value_c;
						$abid[$k]['value_d'] =$value_d;
					}
				}
				if($areaid){
					if($this->groupsdevice_model->addAll($abid)){
						$this->success("区域与idevice关联成功！",U('Groups/edit',array('id'=>$areaid)));
					}else{
						$this->success("区域创建成功，未搜索到相关idevice！",U('Groups/edit',array('id'=>$areaid)));
					}
				}else{
					$this->error("区域与idevice关联失败");
				}
		}
	}

	function edit(){
		$id = intval(I("get.id"));
		$area = $this->groups_model->where(array("id"=>$id))->find();
		$abids = $this->groupsdevice_model->where(array("aid"=>$id))->order("id desc")->select();
		if($abids){
			foreach($abids as$k=>$bids){
				$bid[$k] = $bids['bid'];
			}
			$count=$this->device_model->where(array('id'=>array('in',$bid)))->count();
			$page = $this->page($count,10);
			$devices=$this->device_model->where(array('id'=>array('in',$bid)))
					->limit($page->firstRow . ',' . $page->listRows)
					->order("id DESC")
					->select();
			if($devices){
				foreach($devices as $device){
					$store_id[] = $device['store_id'];
				}
				$stores=$this->store_model->where(array('osid'=>array('in',$store_id)))->select();
				$this->assign("stores", $stores);
			}
			$this->assign("devices", $devices);
	    	$this->assign('page', $page->show('Admin'));
			$this->assign("abids", $abids);
		}

		$bstatus = $this->devicestatus();
		$this->assign("bstatus", $bstatus[1]);
		$this->assign("stype", $bstatus[4]);
		$this->assign("area", $area);
		$this->display();
	}
	function edit_post(){
		if(IS_POST){
				$aream = $this->groups_model->where(array('id'=>I("post.aid")))->find();
				if(I('param.area_type') == 1){
					$bid = I('param.bid');
					$bstatus = $this->devicestatus();
					$value_a = I('param.dtype').'~'.$bstatus[2][I('param.search')]['name'].':'.I('param.keyword');
					$value_b=date("Y-m-d H:i:s");
					$value_c=get_client_ip(0,true);
					$value_d=get_current_admin_id();
				}
				if(I('param.area_type') == 2){
					$value_a = I('param.lt_through').','.I('param.lt_latitude');
					$value_b = I('param.rt_through').','.I('param.rt_latitude');
					$value_c = I('param.rb_through').','.I('param.rb_latitude');
					$value_d = I('param.lb_through').','.I('param.lb_latitude');
					$groupsidevice = $this->groupsdevice_model->where(array('aid'=>I("param.aid")))->order('id desc')->find();
					$bid[0]=$groupsidevice['bid']+1;
				}
				if(I('param.area_type') == 3){
					if(I('param.province')){
						$provinceid = $this->region_model->where(array('code'=>I('param.province')))->find();
						$where= array('province_id'=>$provinceid['code']);
						if(I('param.city')){
							$cityid = $this->region_model->where(array('code'=>I('param.city')))->find();
							$where= array('province_id'=>$provinceid['code'],'city_id'=>$cityid['code']);
							if(I('param.county')){
								$countyid = $this->region_model->where(array('code'=>I('param.county')))->find();
								$where= array('province_id'=>$provinceid['code'],'city_id'=>$cityid['code'],'district_id'=>$countyid['code']);
							}
						}
						$groupsidevice = $this->groupsdevice_model->where(array('aid'=>I("param.aid")))->order('id desc')->find();
						$bid[0]=$groupsidevice['bid']+1;
					}else{
						$this->error("请先选择省份");
					}
					$value_a = $provinceid['code'];
					$value_b = $cityid['code'];
					$value_c = $countyid['code'];
					$value_d = $provinceid['name'].','.$cityid['name'].','.$countyid['name'];

				}
				if(I('param.area_type') == 4){
					$this->devicetemp_model->where(array('barcode is not NULL'))->delete();
					setlocale(LC_ALL, 'en_US.UTF-8');
					if($_FILES["inputcsv"]["name"]){
						$path1 = $_FILES["inputcsv"]["name"];
						$path2 =time().substr($path1,strpos($path1,'.'));
					if(substr($path1,strpos($path1,'.'))!='.csv'){
					   	$this -> error('文件格式不正确');
						}
					}
					if($_FILES["inputcsv"]["size"]>256000){
						$this -> error('文件大小不得超过256KB');
					}
					move_uploaded_file($_FILES["inputcsv"]["tmp_name"],RUNTIME_PATH.$path2);
					$file = RUNTIME_PATH.$path2;
					$arr = $this->getArr($file);
					$carr =count($arr);
					if($carr >=2000){
					   	$this -> error('文件内容过多，请拆分文件导入');
					}
					$ca = count($arr[0]);
					for($i=1;$i<$carr;$i++){
						$str=null;
						for($j=0;$j<$ca;$j++){
							$str[] = $this->expChangeCode($arr[$i][$j]);
						}
						$device['barcode'] = $str[0];
						$device['devid'] = $str[1];
						$this->devicetemp_model->add($device);
					}
						$deviceids = $this->device_model
						->field('d.id')
						->table('yy_device AS d,yy_device_temp AS dt')
						->where("(d.barcode= dt.barcode or d.devid= dt.devid) and d.status=2")
						->select();
					foreach($deviceids as$deviceid){
						$bid[]=$deviceid['id'];
						}
						$value_a='导入数据';
						$value_b=date("Y-m-d H:i:s");
						$value_c=get_client_ip(0,true);
						$value_d=get_current_admin_id();
				}
				$area['created']=date("Y-m-d H:i:s");
				$area['userid']=get_current_admin_id();
				$area['status']=I("post.status");

				if(I('param.area_locking')){
					$this->groupsdevice_model->where(array('bid'=>array('in',$bid)))->delete();
					$this->device_model->where(array('id'=>array('in',$bid)))->save(array('locking'=>'1'));
				}
				if($bid){
					foreach($bid as$k=>$id){
						$abid[$k]['aid'] = I('param.aid');
						$abid[$k]['bid'] = $id;
						$abid[$k]['type']=I('param.area_type');
						$abid[$k]['value_a'] =$value_a;
						$abid[$k]['value_b'] =$value_b;
						$abid[$k]['value_c'] =$value_c;
						$abid[$k]['value_d'] =$value_d;
					}
					if(I('param.area_type' !=2&& 'param.area_type' !=3)){
						$this->groupsdevice_model->where(array('aid'=>I('param.aid'),'bid'=>array('in',$bid)))->delete();
					}
					$cbid = $this->groupsdevice_model->where(array('aid'=>I('param.aid')))->count();
					$area['area_quantity']=count($bid)+$cbid;
				}

				if(I('param.area_type')){
					$area['area_name']=$aream['area_name'];
					$area['area_description']=$aream['area_description'];
				}else{
					$area['area_name']=I('param.area_name');
					$area['area_description']=I('param.area_description');
				}
				if($this->groups_model->where(array('id'=>I('param.aid')))->save($area)){
					if($this->groupsdevice_model->addAll($abid)){
						$this->success("区域与设备关联成功",U('Groups/edit',array('id'=>I("post.aid"))));
					}else{
						$this->success("区域信息修改成功",U('Groups/edit',array('id'=>I("post.aid"))));
					}
				}else{
					$this->error("区域信息修改失败");
				}
		}
	}

	function delete(){
		if(isset($_GET['id'])){
			$id = intval(I("get.id"));
			$abids = $this->groupsdevice_model->where(array("aid"=>$id))->select();
			if($abids){
				foreach($abids as$k=>$bids){
					$bid[$k] = $bids['bid'];
				}
				$this->device_model->where(array('id'=>array('in',$bid)))->save(array('locking'=>'0'));
				$this->groupsdevice_model->where(array("aid"=>$id))->delete();
			}
			if ($this->groups_model->where(array('id'=>$id))->delete()) {
				$this->success("区域删除成功");
			} else {
				$this->error("区域删除失败");
			}
		}
	}
	function delete_device(){
		if(isset($_GET['aid'])&& isset($_GET['bid'])){
			$aid = I("get.aid");
			$bid = I("get.bid");
			if ($this->groupsdevice_model->where(array("aid"=>$aid,"bid"=>$bid))->delete()) {
				$this->device_model->where(array("id"=>$bid))->save(array('locking'=>'0'));
				$count = $this->groupsdevice_model->where(array("aid"=>$aid))->count();
				$this->groups_model->where(array("id"=>$aid))->save(array('area_quantity'=>$count));
				$this->success("删除成功");
			} else {
				$this->error("删除失败");
			}
		}
	}
	function delete_area(){
		if(isset($_GET['aid'])&& isset($_GET['id'])){
			$aid = I("get.aid");
			$id = I("get.id");
			if ($this->groupsdevice_model->where(array("aid"=>$aid,"id"=>$id))->delete()) {
				$count = $this->groupsdevice_model->where(array("aid"=>$aid))->count();
				$this->groups_model->where(array("id"=>$aid))->save(array('area_quantity'=>$count));
				$this->success("删除成功");
			} else {
				$this->error("删除失败");
			}
		}
	}
	function map(){
			$areadevice = $this->groupsdevice_model->where(array("id"=>I('param.id')))->find();
			$area = $this->groups_model->where(array("id"=>$areadevice['aid']))->find();
			$area_type = $area['area_type'];

			if($area_type == 2){
				$lt =explode(',',$areadevice['value_a']);//左上
				$lr =explode(',',$areadevice['value_b']);//右上
				$br =explode(',',$areadevice['value_c']);//右下
				$bl =explode(',',$areadevice['value_d']);//左下
				$where = array(
						array(
						'longitude'=>array('egt',$lt[0]),
						'latitude'=>array('elt',$lt[1]),
						),
						array(
						'longitude'=>array('elt',$lr[0]),
						'latitude'=>array('elt',$lr[1])
						),
						array(
						'longitude'=>array('elt',$br[0]),
						'latitude'=>array('egt',$br[1])
						),
						array(
						'longitude'=>array('egt',$bl[0]),
						'latitude'=>array('egt',$bl[1])
						)
					);

			}
			if($area_type == 3){
				if($areadevice['value_a']){
					$where = array(
						array(
						'province_id'=>array('eq',$areadevice['value_a']),
						)
					);
				}
				if($areadevice['value_b']){
					$where = array(
						array(
						'city_id'=>array('eq',$areadevice['value_b']),
						)
					);
				}
				if($areadevice['value_c']){
					$where = array(
						array(
						'district_id'=>array('eq',$areadevice['value_c']),
						)
					);
				}
			}
			$coordinates = $this->store_model->where($where)->select();
			$this->assign("area_type", $area_type);
			$this->assign("areadevice", $areadevice);
			$this->assign("coordinates", $coordinates);
			$this->display();
	}
	public function up(){
    	if (I("get.id")) {
    		$rst = $this->groups_model->where(array('id'=>I("get.id")))->setField('status','1');
    		if ($rst) {
    			$this->success("群组启用成功！");
    		} else {
    			$this->error('群组启用失败！');
    		}
    	} else {
			$this->error($this->groups_model->getError());
    	}
    }

    public function down(){
    	if (I("get.id")) {
    		$rst = $this->groups_model->where(array('id'=>I("get.id")))->setField('status','0');
    		if ($rst) {
    			$this->success("群组停用成功！");
    		} else {
    			$this->error('群组停用失败！');
    		}
    	} else {
			$this->error($this->groups_model->getError());
    	}
    }
}